require"manage"

module(...,package.seeall)

local smatch,schar = string.match,string.char


local function addparaver()
	nvm.set("paraver",nvm.get("paraver")+1)
end

local function qryloc(p)
	deveventrsp(p)
	-- linkout.locReport(protoair.QRYPOS)
end

local function restore(p)
	sys.publish("SVR_RESTORE_IND","SVR")
	deveventrsp(p)
end

local setclked
local function datetime(p)
	--print("Server datetime p",p.year,p.month,p.day,p.hour,p.min,p.sec)
	if not setclked then
		misc.setClock(p)
		setclked = true
	end
end


function procMsg(socketClient)
	local r,data
	while true do
		r,data = socketClient:recv(2000)
		
		if r and data~="timeout" then
			log.info("--zbb--linkin.procMsg <<<:",r,string.toHex(data))
			local packet = protoairdef.unpack(data)
			-- if packet and packet.id and cmds[packet.id] then
			-- 	packet.topic = data.topic
			-- 	cmds[packet.id](packet)
			-- 	if linkout.waitForSend() then return true end
			-- end
			if linkout.waitForSend() then return true end
		else
			break
		end
	end
	
	return data=="timeout" or r
end
